package com.xiaoyu.commonlib.ui.dialog;

import android.content.Context;
import android.text.TextUtils;

import com.xiaoyu.commonlib.R;


/**
 * @author sm
 * @date 创建时间 2018/7/31
 * @Description
 */
public class TitleDetailsDialog extends BaseDialog {
    private String title;
    private String details, LeftText, RightText;
    private OnClickListener onClickListener;

    //修改标题
    public TitleDetailsDialog(Context context, String title, OnClickListener onClickListener) {
        super(context);
        this.title = title;
        this.onClickListener = onClickListener;
    }

    //修改标题与左侧文字
    public TitleDetailsDialog(Context context, String title, String LeftText, OnClickListener onClickListener) {
        this(context, title, onClickListener);
        this.LeftText = LeftText;
    }

    //修改标题、左侧文字与右侧文字
    public TitleDetailsDialog(Context context, String title, String LeftText, String RightText, OnClickListener onClickListener) {
        this(context, title, LeftText, onClickListener);
        this.RightText = RightText;
    }

    public TitleDetailsDialog setLeftTextColor(int color) {
        if (getmLeftTextView() != null)
            getmLeftTextView().setTextColor(color);
        return this;
    }

    public TitleDetailsDialog addDetails(String details) {
        this.details = details;
        return this;
    }

    @Override
    protected String getTitleText() {
        return title;
    }

    @Override
    protected String getDetailsText() {
        return details;
    }

    @Override
    protected String getLeftText() {
        if (!TextUtils.isEmpty(LeftText))
            return LeftText;
        return getmContext().getResources().getString(R.string.cancel);
    }

    @Override
    protected String getRightText() {
        if (!TextUtils.isEmpty(RightText)) {
            return RightText;
        }
        return getmContext().getResources().getString(R.string.confirm);
    }

    @Override
    protected void leftClick() {
        dismiss();
    }

    @Override
    protected void rightClick() {
        if (onClickListener != null)
            onClickListener.setOnClick();
        dismiss();
    }

    /**
     * 设置接口回调
     */
    public interface OnClickListener {
        void setOnClick();
    }
}
